package com.atguigui.leetcode1;

/**
 * 2562.找出数组的串联值
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/10/12 10:04
 */
public class P2562FindTheArrayConcatenationValue {
    public static void main(String[] args) {
        Solution solution = new P2562FindTheArrayConcatenationValue().new Solution();
        int[] ans = {7, 52, 2, 4};
        solution.findTheArrayConcVal(ans);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public long findTheArrayConcVal(int[] nums) {
            int index = nums.length % 2;
            long sum = 0;
            if (index == 0) {
                index = nums.length / 2;
                for (int i = 0; i < index; i++) {
                    sum += Long.valueOf(nums[index - i - 1] + "" + nums[index + i]);
                }
            } else {
                index = nums.length / 2;
                for (int i = 0; i < index; i++) {
                    sum += Long.valueOf(nums[index - i - 1] + "" + nums[index + i + 1]);
                }
                sum += nums[index];
            }


            return sum;
        }
    }
}
